/**
 * @name: nFormatter
 * @test: test font
 * @msg: 处理图表坐标轴上数据过大，导致显示不完整。进行位数转化
 * @param {type}
 * @return:
 */
export const nFormatter = function nFormatter(num, digits = 2) {
  const si = [
    {
      value: 1,
      symbol: ''
    },
    {
      value: 1e3,
      symbol: '千'
    },
    {
      value: 1e4,
      symbol: '万'
    },
    {
      value: 1e8,
      symbol: '亿'
    }
  ]
  const rx = /\.0+$|(\.[0-9]*[1-9])0+$/
  let i
  for (i = si.length - 1; i > 0; i--) {
    if (Math.abs(num) >= si[i].value) {
      break
    }
  }

  return (num / si[i].value).toFixed(digits).replace(rx, '$1') + si[i].symbol
}
